package com.swanclouds.redfish.common.utils;

/**
 * 字符串操作工具类
 *
 * @author 张立强
 */
public class StringHepler {

    /**
     * 截取字符串
     * @param split 分割
     * @param src 字符串
     * @param left 从前开始还是从后开始
     * @return 截取字符串
     */
    public static String substring(String split, String src, boolean left) {
        if (left) {
            return src.substring(src.indexOf(split) + 1, src.length());
        } else {
            return src.substring(src.lastIndexOf(split) + 1, src.length());
        }
    }

    public static boolean isEmpty(CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

    public static boolean isNotEmpty(CharSequence cs) {
        return !isEmpty(cs);
    }

    public static boolean isBlank(CharSequence cs) {
        int strLen;
        if (cs != null && (strLen = cs.length()) != 0) {
            for(int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(cs.charAt(i))) {
                    return false;
                }
            }

            return true;
        } else {
            return true;
        }
    }

    public static boolean isNotBlank(CharSequence cs) {
        return !isBlank(cs);
    }


}
